<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">


<ui:composition template="/layout/template.xhtml">

	<ui:define name="title">
		<h:outputText value="#{appMsg['title.list.drivers']}" />
	</ui:define>

	<ui:define name="content">
		<h:panelGrid columns="2">
			<p:panel styleClass="peel-no-border">
				<p:panel header="#{appMsg['title.list.drivers']}" id="searchPanel">
					<h:form id="search">
						<ui:decorate template="/sub-driver-search-fields.xhtml" />
						<p:commandButton type="submit" value="#{appMsg.search}" update=":searchPanel,:listPanel"
							actionListener="#{driversView.search}" id="search"/>
						<p:commandButton type="reset" value="#{appMsg.reset}" update=":searchPanel,:listPanel" id="reset"/>
						<p:commandButton type="submit" value="#{appMsg.clear}" update=":searchPanel,:listPanel"
							actionListener="#{driversView.clearSearchForm}" id="clear"/>
					</h:form>
				</p:panel>
			</p:panel>
			
			<p:panel id="editPanel" styleClass="peel-no-border">
				<p:panel rendered="#{driversView.editMode}" header="#{appMsg['title.update.driver']}">
					<h:form id="formDriver">
						<ui:decorate template="/sub-driver.xhtml" />
						<p:commandButton id="merge" actionListener="#{driversView.updateDriver}"
							update=":editPanel :listPanel"
							value="#{driverHome.driver.id ne null ? appMsg['update'] : appMsg['create']}" />
						<p:commandButton id="delete" actionListener="#{driversView.deleteDriver}" value="#{appMsg['delete']}"
							rendered="#{driverHome.driver.id ne null}" process="@this" partialSubmit="true"
							update=":editPanel :listPanel" onclick="confirm('#{appMsg['confirm.delete']} #{appMsg['driver']}')" />
						<p:spacer width="5px" />
						<p:commandButton id="cancel" process="@this" value="#{appMsg['cancel']}" update=":editPanel :listPanel"
							actionListener="#{driversView.cancelEditDriver}" />
					</h:form>
				</p:panel>
			</p:panel>
		</h:panelGrid>



		<h:panelGroup id="listPanel">
			<h:form id="form">
				<p:dataTable id="dataTable" value="#{driversHome.drivers}" var="p" lazy="true" paginator="true" rows="10"
					paginatorPosition="bottom" sortBy="#{p.id}" rowKey="#{p.id}">

					<f:facet name="header">
						<p:commandButton id="deleteAllButton" value="#{appMsg['delete.drivers']}" icon="ui-icon-circle-close"
							onstart="return confirm('#{appMsg['confirm.deletes']}')" update="@form"
							actionListener="#{driversView.deleteAllSelectedDriver}" styleClass="itemSelected"
							disabled="#{!driversView.hasSelectedDrivers}" />
					</f:facet>

					<p:column sortBy="#{p.id}">
						<h:selectBooleanCheckbox value="#{driversView.selectedDrivers[p]}">
							<p:ajax update="@(.itemSelected)" />
						</h:selectBooleanCheckbox>
					</p:column>
					<!-- warning equals on Driver ! -->

					<p:column sortBy="#{p.id}">
						<f:facet name="header">
							<h:outputText value="#{appMsg['driver.id']}" />
						</f:facet>
						<h:outputLink value="#{request.contextPath}/driver.faces">
							<f:param name="driverId" value="#{p.id}" />
							<h:outputText value="#{p.id}" />
						</h:outputLink>
						<p:spacer width="10px" />
						<p:commandButton value="edit" update=":editPanel :listPanel" disabled="#{driversView.editMode}"
							actionListener="#{driversView.setEditDriverById(p.id)}" >
						</p:commandButton>
					</p:column>
					<ui:decorate template="/sub-driver-columns.xhtml" />
				</p:dataTable>
			</h:form>
		</h:panelGroup>

	</ui:define>
</ui:composition>
</html>
